package com.cleaningcloud.cld.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import com.cleaningcloud.cld.domain.CldAssets;
import com.cleaningcloud.cld.service.ICldAssetsService;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.common.core.web.page.TableDataInfo;

/**
 * 资产信息Controller
 * 
 * @author cleaningcloud
 * @date 2024-10-06
 */
@RestController
@RequestMapping("/assets")
public class CldAssetsController extends BaseController
{
    @Autowired
    private ICldAssetsService cldAssetsService;

    /**
     * 查询资产信息列表
     */
    @RequiresPermissions("cld:assets:list")
    @GetMapping("/list")
    public TableDataInfo list(CldAssets cldAssets)
    {
        startPage();
        List<CldAssets> list = cldAssetsService.selectCldAssetsList(cldAssets);
        return getDataTable(list);
    }

    /**
     * 导出资产信息列表
     */
    @RequiresPermissions("cld:assets:export")
    @Log(title = "资产信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CldAssets cldAssets)
    {
        List<CldAssets> list = cldAssetsService.selectCldAssetsList(cldAssets);
        ExcelUtil<CldAssets> util = new ExcelUtil<CldAssets>(CldAssets.class);
        util.exportExcel(response, list, "资产信息数据");
    }

    /**
     * 获取资产信息详细信息
     */
    @RequiresPermissions("cld:assets:query")
    @GetMapping(value = "/{assetsId}")
    public AjaxResult getInfo(@PathVariable("assetsId") Long assetsId)
    {
        return success(cldAssetsService.selectCldAssetsByAssetsId(assetsId));
    }

    /**
     * 获取资产列表
     */
    @GetMapping("/getList")
    public AjaxResult getList()
    {
        return success(cldAssetsService.getList());
    }

    /**
     * 新增资产信息
     */
    @RequiresPermissions("cld:assets:add")
    @Log(title = "资产信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CldAssets cldAssets)
    {
        return toAjax(cldAssetsService.insertCldAssets(cldAssets));
    }

    /**
     * 修改资产信息
     */
    @RequiresPermissions("cld:assets:edit")
    @Log(title = "资产信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CldAssets cldAssets)
    {
        return toAjax(cldAssetsService.updateCldAssets(cldAssets));
    }

    /**
     * 删除资产信息
     */
    @RequiresPermissions("cld:assets:remove")
    @Log(title = "资产信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{assetsIds}")
    public AjaxResult remove(@PathVariable Long[] assetsIds)
    {
        return toAjax(cldAssetsService.deleteCldAssetsByAssetsIds(assetsIds));
    }
}
